package com.ray.controller;

import com.ray.entity.RespBean;
import com.ray.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@Api(tags = "用户接口管理")//value没明显效果
public class UserController {


    @GetMapping("/index")
    @ApiOperation("首页")
    public String index(){
        return "index";
    }

    @GetMapping("getUser")
    @ApiOperation("获取用户")
    public User getUser(){
        User user = new User();
        user.setId(2);
        user.setNickname("zhangsan");
        return user;
    }


    @PostMapping("/addUser")
    @ApiOperation("添加用户的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户名", defaultValue = "李四"),
            @ApiImplicitParam(name = "phone", value = "用户电话", defaultValue = "13438393333", required = true)
    }
    )
    public RespBean addUser(String username, @RequestParam(required = true) String phone) {
        return RespBean.success("添加成功");
    }


    @GetMapping("/findById/{id}")
    @ApiOperation("查询用户")
    @ApiImplicitParam(name = "id", value = "用户id", defaultValue = "99", required = true)
    public User getUserById(@PathVariable Integer id) {
        User user = new User();
        user.setId(id);
        return user;
    }

    @PutMapping("/update")
    @ApiOperation("更新用户")
    public User updateUserById(@RequestBody User user) {
        System.out.println(user.getUsername());
        return user;
    }

    /**
     * 用户登入
     *
     * @param username: 用户名
     * @param password: 密码
     * @return
     */
//    @ApiOperation(value = "用户登入", notes = "接收参数用户名和密码,登入成功后,返回JWTToken")
//    @PostMapping("/login")
//    public RespBean login(@NotBlank(message = "账号必填") String username,
//                              @NotBlank(message = "密码必填") String password,
//                              HttpServletRequest request) {
//        return RespBean.success("登录成功");
//    }





}
